package com.zzptc.zzsgz.bdsjws.Adapter;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.FamilyProtectActivity;
import com.zzptc.zzsgz.bdsjws.activities.OneKeySOSActivity;
import com.zzptc.zzsgz.bdsjws.vo.BBX;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/24 0024.
 */

public class BBXAdapter extends RecyclerView.Adapter<BBXAdapter.MyViewHolder>{
    List<BBX> list;
    public BBXAdapter(List<BBX> list){
        this.list = list;
    }



    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.bbx_item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final BBX bbx = list.get(position);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bbx.getName().equals("家人守护")) {
                    Intent intent = new Intent(MyApplication.getContext(), FamilyProtectActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApplication.getContext().startActivity(intent);
                }



            }
        });



        int pic_int = MyApplication.getContext().getResources().getIdentifier(bbx.getIcon() , "mipmap" ,
                MyApplication.getContext().getPackageName());
//        Drawable drawable = MyApplication.getContext().getResources().getDrawable(pic_int);
        Drawable drawable = ContextCompat.getDrawable(MyApplication.getContext() , pic_int);
        holder.iv_bbx_pic.setImageDrawable(drawable);
        holder.tv_bbx_name.setText(bbx.getName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.iv_bbx_pic)
        ImageView iv_bbx_pic;
        @BindView(R.id.tv_bbx_name)
        TextView tv_bbx_name;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);

        }
    }
}
